import axios from "axios"
const state = {
    adminName: localStorage.adminName,
    token: localStorage.token,
    adminLog: [], // 管理员登陆日志
    // pageSum: 1,
    adminList: []

}
const mutations = {
    // changePageInfo(state, pageSum) {
    //     state.pageSum = pageSum
    // },
    changeAdminInfo(state, { adminName, token }) {
        state.adminName = localStorage.adminName = adminName
        state.token = localStorage.token = token
    },
    outAdminInfo(state) {
        localStorage.clear() // 清除所有信息
        state.adminName = state.token = null;
    },
    changeAdminLog(state, adminLog) {
        state.adminLog = adminLog

    },
    changeAdminList(state, adminList) {
        state.adminList = adminList
    }
}
const actions = {
    // 管理员登录
    login({ commit }, that) {
        axios.post('/login', that.adminInfo)
            .then((data) => {
                if (data.ok === 1) {
                    // console.log(data);
                    commit('changeAdminInfo', data)
                } else {
                    that.$message.error("账号或密码错误")
                }
            })
    },
    getAdminLog({ commit }, params) {
        axios.get('/adminLog', {
            params
        })
            .then(data => {
                // console.log(data.adminLog);
                commit('changeAdminLog', data.adminLog)
                // commit('changePageInfo', data.pageSum) // 设置总页数

            })
    },
    deleleAdminLog({ dispatch }, id) {
        axios.delete('/adminLog/' + id, {
            params: {
                id
            }
        })
            .then(data => {
                if (data.ok === 1) {
                    dispatch('getAdminLog');

                }
                console.log(data);
            })

    },
    getAdminList({ commit }, params) {
        axios.get('/adminList', {
            params
        }).then(data => {
            commit('changeAdminList', data.adminList);
        })
    }



}
export default {
    state,
    actions,
    mutations
}